﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class AnswerInChannelPromptsController : ControllerBase
    {

        private readonly IAnswerInChannelPromptAppService _app;
        public AnswerInChannelPromptsController(IAnswerInChannelPromptAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("prompts/{id:Guid}")]
        public ActionResult<AnswerInChannelPromptDto> Get([FromRoute] Guid id, [FromQuery] string include = "")
        {
            AnswerInChannelPromptDto answerInChannelPrompt = _app.Get(id, include);
            return Ok(answerInChannelPrompt);
        }

        [HttpGet]
        [Route("answerInChannels/{answerInChannelId:Guid}/prompts")]
        public ActionResult<IEnumerable<AnswerInChannelPromptDto>> GetList([FromRoute] Guid answerInChannelId, [FromQuery]string include = "")
        {
            IEnumerable<AnswerInChannelPromptDto> list = _app.GetList(answerInChannelId, include);
            return Ok(list);
        }

        [HttpPut]
        [Route("prompts/{id:Guid}")]
        public ActionResult<AnswerInChannelPromptDto> Put([FromRoute] Guid id, [FromBody] AnswerInChannelPromptUpdateDto dto)
        {
            AnswerInChannelPromptDto answerInChannelPrompt = _app.Update(id, dto);
            return Ok(answerInChannelPrompt);
        }

        [HttpPost]
        [Route("answerInChannels/{answerInChannelId:Guid}/prompts")]
        public ActionResult<AnswerInChannelPromptDto> Post([FromRoute] Guid answerInChannelId, [FromBody] AnswerInChannelPromptCreateDto dto)
        {
            AnswerInChannelPromptDto answerInChannelPrompt = _app.Add(answerInChannelId, dto);
            return CreatedAtAction(nameof(Get), new { id = answerInChannelPrompt.Id }, answerInChannelPrompt);
        }

        [HttpDelete]
        [Route("prompts/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
